using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ComputaGuru.SpEAd
{
    public partial class AttributeOperatorSelector : Form
    {
        private EA.Element activeElement = null;
        private List<AttributeDescriptor> selectedAttributes = new List<AttributeDescriptor>();
        private List<OperationDescriptor> selectedMethods = new List<OperationDescriptor>();
        private AttributeOperatorSelectorMode selectorMode = AttributeOperatorSelectorMode.Copy;
        private SelectionMode selectionMode = SelectionMode.MultiExtended;

        public SelectionMode SelectionMode
        {
            get { return this.selectionMode; }
            set { this.selectionMode = value; }
        }

        internal AttributeOperatorSelectorMode Mode
        {
            get { return this.selectorMode; }
            set { this.selectorMode = value; }
        }

        public List<AttributeDescriptor> SelectedAttributes
        {
            get { return this.selectedAttributes; }
            set { this.selectedAttributes = value; }
        }

        public List<OperationDescriptor> SelectedOperations
        {
            get { return this.selectedMethods; }
            set { this.selectedMethods = value; }
        }

        public EA.Element ActiveElement
        {
            get { return this.activeElement; }
            set { this.activeElement = value; }
        }

        public AttributeOperatorSelector()
        {
            InitializeComponent();
        }

        private void AttributeOperatorSelector_Load(object sender, EventArgs e)
        {
            if (this.ActiveElement != null)
            {
                foreach (EA.Attribute currentAttribute in this.ActiveElement.Attributes)
                {
                    this.attributeList.Items.Add(new AttributeDescriptor(currentAttribute));
                }

                foreach (EA.Method currentMethod in this.ActiveElement.Methods)
                {
                    this.operationList.Items.Add(new OperationDescriptor(currentMethod));
                }
            }
        }

        private void selectAttributeAll_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.attributeList.Items.Count; i++)
            {
                this.attributeList.SetSelected(i, true);
            }
        }

        private void selectAttributeNone_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.attributeList.Items.Count; i++)
            {
                this.attributeList.SetSelected(i, false);
            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            foreach (AttributeDescriptor currentAttribute in this.attributeList.SelectedItems)
            {
                this.SelectedAttributes.Add(currentAttribute);
            }

            foreach (OperationDescriptor currentOperation in this.operationList.SelectedItems)
            {
                this.SelectedOperations.Add(currentOperation);
            }

            this.DialogResult = DialogResult.OK;
            this.Hide();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Hide();
        }

        private void selectNoneOperations_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.operationList.Items.Count; i++)
            {
                this.operationList.SetSelected(i, false);
            }
        }

        private void selectAllOperations_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.operationList.Items.Count; i++)
            {
                this.operationList.SetSelected(i, true);
            }
        }
    }
}